package com.homedo.odin.solution.enumcode.usersafe;

import java.util.Arrays;
import lombok.Getter;

/**
 * Created by liyi on 2018/5/22. DESCRIPTION  bizCode PRODUCT 产品库
 */
@Getter
public enum BizCodeEnum {

    PRODUCT("PRODUCT", "产品库");

    private String dbValue;
    private String displayValue;

    BizCodeEnum(String dbValue, String displayValue) {
        this.dbValue = dbValue;
        this.displayValue = displayValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(String dbValue) {
        return Arrays.stream(BizCodeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(BizCodeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(String dbValue) {
        return Arrays.stream(BizCodeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
